package pap;

public class Point {

	private double[] coordinates;

	public Point(double[] coordinates) {
		this.coordinates = coordinates;
	}

	public double getCoordinate(int index) {
		return coordinates[index];
	}

	public int getDimension() {
		return coordinates.length;
	}

	/**
	 * Calculates the distance between origin and the current point.
	 * 
	 * @return distance
	 */
	public double distanceFromOrigin() {
		double inc = 0;
		for (int i = 0; i < coordinates.length; i++) {
			inc += Math.pow(coordinates[i], 2);
		}
		return Math.sqrt(inc);
	}

	/**
	 * Calculates the distance between the specified point and the current
	 * point.
	 * 
	 * @param p
	 * @return distance
	 */
	public double distanceFrom(Point p) {
		double inc = 0;
		for (int i = 0; i < coordinates.length; i++) {
			inc += Math.pow(coordinates[i] - p.coordinates[i], 2);
		}
		return Math.sqrt(inc);
	}

}